<?php
$pos = strpos($_SERVER['SERVER_NAME'], 'freeteam.streams.com');
if($pos === false){
	include_once('includes/classes/config.inc.php');
}else{
	include_once('includes/classes/config-local.inc.php');
}
include_once('includes/classes/class.database.php');
//include_once(abspath.'/includes/sitefuncs/securesession.class.php');
include_once(abspath.'/includes/funcs/homefuncs.php');
include_once(abspath.'/includes/funcs/function_absolute.php');

header('Content-Type: application/json');
$iconCat = "/images/icon-livematches.png";
$titleHeader = "Live Matches";
$aboutChannel = array();
$catID = 0;
if(!empty($_GET['c'])){
	if(is_numeric($_GET['c'])){
		$category = getCategory($_GET['c']);
		$catID = $_GET['c'];
	}
	$aboutChannel = getAboutChannelCategory($catID);
	if(!empty($category)){
		if($category['icon'] != null) $iconCat = "/upload/".$category['icon'];
		$titleHeader = "Live ".$category['alias'];
	}
	$rows = listChannels('channels.created desc',$_GET['c']);
	$data = array();
	$cnt = 0;
	while ($record= $db->fetch_array($rows)) {
		$embled = getEmbledChannel($record['channel_id']);
		$tData = array(
			'channel_id'=>$record['channel_id'],
			'url_icon'=>$record['url_icon'],
			'channel_type_name'=>$record['channel_type_name'],
			'status'=>$record['status'],
			'hour'=>$record['hour'],
			'minutes'=>$record['minutes'],
			'name_of_channel'=>$record['name_of_channel']
		);
		
		$data[$cnt] = $tData;
		$data[$cnt]['flash'] = $embled;

		$cnt++;
	}

	echo @json_encode(array(
		'error'=>!empty($data) ? false : true,
		'message'=>!empty($data) ? 'Get channel success' : 'There are no live events in this category. Please try a different category or wait atleast 30 mins before the start of event.',
		'data'=>$data,
		'titleHeader'=>$titleHeader,
		'aboutChannel'=>$aboutChannel,
		'icon'=>$iconCat
		
	));

}else{
	echo @json_encode(array(
		'error'=>true,
		'icon'=>$iconCat,
		'titleHeader'=>$titleHeader,
		'aboutChannel'=>$aboutChannel,
		'message'=>'There are no live events in this category. Please try a different category or wait atleast 30 mins before the start of event.'
	));
	
	
}
	

?>